# 字典
my_dict = {}
# <class 'dict'> {}
print(type(my_dict), my_dict)

my_dict = dict()
# <class 'dict'> {}
print(type(my_dict), my_dict)

# 重复key，后面的key覆盖前面的
my_dict = {'name3': 56, 'name2': 66, 'name4': 76, 'name4': 86}
print(my_dict)

print(my_dict['name4'])

my_dict = {'name3': 56, 'name2': 66, 'name4': 76, }
# 新增元素
my_dict['name5'] = 86
print(my_dict)

# 修改元素
my_dict['name4'] = 77
print(my_dict)
# None
print(my_dict.get('sex'))
# 返回默认值
print(my_dict.get('sex', '男'))

# 删除元素
my_dict.pop("name4")
print(my_dict)

# 获取keys
res = my_dict.keys()
# dict_keys(['name3', 'name2', 'name5'])
print(res)
# for i in res:
#     print(i)

for key in my_dict:
    print(f"{key}=={my_dict[key]}")

# 每一项 是一个元组
for item in my_dict.items():
    print(f"{item}")

for key, val in my_dict.items():
    print(f"{key}=={val}")

